package client;

import common.LoginPassword;
import common.User;

import javax.swing.*;
import javax.xml.crypto.Data;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Igor Demidov
 * Date: 24.02.13
 * Time: 11:38
 */
public class RegistrationPageGUI {
    private JPanel panel1;
    private JPasswordField passwordTextField;
    private JTextField loginTextField;
    private JTextField phoneTextField;
    private JTextField nameTextField;
    private JTextField surnameTextField;
    private JButton doneButton;

    RegistrationPageGUI(final MainClient client) {
        final JFrame frame = new JFrame("Registration Page");
        frame.setContentPane(this.panel1);
        frame.pack();
        frame.setVisible(true);
        doneButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User user = new User(nameTextField.getText(), surnameTextField.getText(),
                        new Date(), phoneTextField.getText(), new LoginPassword(loginTextField.getText(), new String(passwordTextField.getPassword())));
                try {
                    if (client.doRegister(user)) {
                        frame.setVisible(false);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            }
        });
    }
}
